
package com.yuan.dialog;

import com.yuan.graduate.R;
import com.yuan.view.ProgressView;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 自定义ProgressDialog
 * 
 * @author YUAN
 */
public class CustomProgressDialog extends CustomDialog implements android.view.View.OnClickListener {
    private ProgressView updateImg;
    private TextView updateMsg;
    private ImageView updateClose;

    public CustomProgressDialog(Context context) {
        super(context);
        setContentView(R.layout.custom_dialog_update);
        initView();
    }

    private void initView() {
        setCanceledOnTouchOutside(false);
        updateImg = (ProgressView) findViewById(R.id.update_img);
        updateMsg = (TextView) findViewById(R.id.update_msg);
        updateClose = (ImageView) findViewById(R.id.update_close);
        updateClose.setOnClickListener(this);
        this.setCancelable(false);
    }

    public void setImageResource(int resId) {
        if (updateImg != null) {
            updateImg.setImageResource(resId);
        }
    }

    public void setUpdateMsg(String msg) {
        if (updateMsg != null) {
            updateMsg.setText(msg);
        }
    }

    public void setUpdateMsg(int msgId) {
        if (updateMsg != null) {
            updateMsg.setText(msgId);
        }
    }

    public void postDelayed(Runnable runnable, long delayMillis)
    {
        if (updateImg != null)
        {
            updateImg.postDelayed(runnable, delayMillis);
        }
    }

    public void clearAnimation() {
        if (updateImg != null)
        {
            updateImg.clearAnimation();
        }
    }

    public void hiddenClose() {
        if (updateClose != null)
        {
            updateClose.setVisibility(View.INVISIBLE);
        }
    }

    public void showClose() {
        if (updateClose != null) {
            updateClose.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.update_close:
                this.dismiss();
                break;
            default:
                break;
        }
    }

    @Override
    public void dismiss() {
        super.dismiss();
        onDestroy();
    }

    public void onDestroy() {
        // TODO Auto-generated method stub
        updateImg = null;
        updateMsg = null;
        updateClose = null;
    }
}
